package serverapp

import (
	"context"
)

//服务类型
type ServiceType int

const (
	MicroType ServiceType = iota
	GrpcType
)

//Option 选项
type Option func(opts *Options)

//Options 选项类
type Options struct {
	context          context.Context
	srvCfg           ServiceConf
	webCfg           WebConf
	serviceType      ServiceType
	signal           bool
	disableDebugAddr bool
	cmdFn            OnCmdFunc
}

//ServiceConf micro服务配置
type ServiceConf struct {
	//`json:""`
	SrvName   string `json:"serviceName"`
	Registry  string `json:"registry"`
	TTL       int    `json:"ttl"`
	Interval  int    `json:"interval"`
	Addr      string `json:"addr"`
	Version   string `json:"version"`
	Command   string `json:"command"`
	DebugAddr string `json:"debugAddr"`
}

//WebConf web服务配置
type WebConf struct {
	SrvName  string `json:"serviceName"`
	Registry string `json:"registry"`
	TTL      int    `json:"ttl"`
	Interval int    `json:"interval"`
	Addr     string `json:"addr"`
	Version  string `json:"version"`
	Command  string `json:"command"`
}

//WithCfg 设置配置文件名
func WithCfg(cfg ServiceConf) Option {
	return func(o *Options) {
		o.srvCfg = cfg
	}
}

// 自定义进程退出的钩子，signal为true表示由micro底层来捕获进程退出事件，否则由应用层捕获进程退出事件
func WithQuitHandler(signal bool) Option {
	return func(o *Options) {
		o.signal = signal
	}
}

func WithCmdFunc(fn OnCmdFunc) Option {
	return func(o *Options) {
		o.cmdFn = fn
	}
}

//WithServiceType 设置服务类型
func WithServiceType(serviceType ServiceType) Option {
	return func(o *Options) {
		o.serviceType = serviceType
	}
}

//WithCfg 设置配置文件名
func WithWebCfg(cfg WebConf) Option {
	return func(o *Options) {
		o.webCfg = cfg
	}
}

//WithContext 设置windserver
func WithContext(ctx context.Context) Option {
	return func(o *Options) {
		o.context = ctx
	}
}

//禁用调试端口
func WithDisableDebugAddr(disable bool) Option {
	return func(o *Options) {
		o.disableDebugAddr = disable
	}
}
